package com.ruoyi.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CdTopicQuestion;
import com.ruoyi.course.service.ICdTopicQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言板Controller
 * 
 * @author ruoyi
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/question/question")
public class CdTopicQuestionController extends BaseController
{
    @Autowired
    private ICdTopicQuestionService cdTopicQuestionService;

    /**
     * 查询留言板列表
     */
    @PreAuthorize("@ss.hasPermi('question:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(CdTopicQuestion cdTopicQuestion)
    {
        startPage();
        List<CdTopicQuestion> list = cdTopicQuestionService.selectCdTopicQuestionList(cdTopicQuestion);
        return getDataTable(list);
    }

    /**
     * 导出留言板列表
     */
    @PreAuthorize("@ss.hasPermi('question:question:export')")
    @Log(title = "留言板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CdTopicQuestion cdTopicQuestion)
    {
        List<CdTopicQuestion> list = cdTopicQuestionService.selectCdTopicQuestionList(cdTopicQuestion);
        ExcelUtil<CdTopicQuestion> util = new ExcelUtil<CdTopicQuestion>(CdTopicQuestion.class);
        util.exportExcel(response, list, "留言板数据");
    }

    /**
     * 获取留言板详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:question:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return success(cdTopicQuestionService.selectCdTopicQuestionByQuestionId(questionId));
    }

    /**
     * 新增留言板
     */
    @PreAuthorize("@ss.hasPermi('question:question:add')")
    @Log(title = "留言板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CdTopicQuestion cdTopicQuestion)
    {
        return toAjax(cdTopicQuestionService.insertCdTopicQuestion(cdTopicQuestion));
    }

    /**
     * 修改留言板
     */
    @PreAuthorize("@ss.hasPermi('question:question:edit')")
    @Log(title = "留言板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CdTopicQuestion cdTopicQuestion)
    {
        return toAjax(cdTopicQuestionService.updateCdTopicQuestion(cdTopicQuestion));
    }

    /**
     * 删除留言板
     */
    @PreAuthorize("@ss.hasPermi('question:question:remove')")
    @Log(title = "留言板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(cdTopicQuestionService.deleteCdTopicQuestionByQuestionIds(questionIds));
    }
}
